<!--
 * @Description: 6C设备管理-产品列表
 * @Author: Wang zhongwang
 * @Date: 2023-02-20
 * @LastEditTime: 2024-02-05 15:04:56
 * @LastEditors: zhangweili zhang_weili@uxsino.com
-->
<template>
  <!--  -->
  <div class="app-container">
    <div class="app-containerInner">
      <div class="header">
        <div class="line" />
        <div class="text">产品管理</div>
      </div>
      <!-- filter -->
      <filter-form :form="listQuery" :data="filterData" :has-default-operation="false" style="margin-bottom: 10px;">
        <el-button type="primary" size="middle" class="searchBtns" icon="el-icon-search" @click="getListPage">查询</el-button>
        <!--      <el-button icon="el-icon-upload2" plain size="mini" type="info"-->
        <!--                   @click="handleImport">-->
        <!--          导入-->
        <!--      </el-button>-->
        <ul class="tabIcons">
          <li class="tabBtnIcons" :class="{ activeIcon: isActiveBtn }" @click="handleClickTab('first')"><i class="el-icon-menu" /></li>
          <li class="tabBtnIcons" :class="{ activeIcon: !isActiveBtn }" @click="handleClickTab('second')"><i class="el-icon-s-fold" /></li>
          <!--          <li class="tabBtnIcons" :class="{ activeIcon: !isActiveBtn }" @click="handleClickTab('second')"><i class="el-icon-menu" /></li>-->
        </ul>
      </filter-form>
      <!-- filter -->

      <div ref="main" class="tabmain" :class="{ firstmain: !isActiveBtn }">
        <div class="v-flex" style="height: 100%;">
          <el-table
            :key="tableKey"
            v-loading="listLoading"
            :data="list"
            border
            fit
            highlight-current-row
            tooltip-effect="dark"
            :height="height"
            style="width: 100%;">
            <el-table-column label="序号" type="index" width="50" align="center" />
            <el-table-column align="center" label="产品名称" prop="productName" />
            <!-- <el-table-column align="center" label="产品标识" prop="productIdentification" width="180" /> -->
            <el-table-column align="center" label="产品型号" prop="model" />
            <el-table-column align="center" label="数据格式" prop="dataFormat" width="150" />
            <!-- <el-table-column align="center" label="厂商ID" prop="manufacturerId" width="180" /> -->
            <el-table-column align="center" label="厂商" prop="manufacturerName" />
            <!-- <el-table-column align="center" label="产品描述" prop="model" width="180" /> -->
            <el-table-column align="center" label="协议类型" prop="protocolType" width="180" />
            <el-table-column
              prop="tag"
              label="状态"
              align="center"
              width="150">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.common_status" :value="scope.row.status" />
              </template>
            </el-table-column>
            <el-table-column align="center" fixed="right" label="操作" width="130">
              <template slot-scope="scope">
                <el-tooltip class="item" content="删除" effect="light" placement="top">
                  <el-button
                    icon="el-icon-delete"
                    size="mini"
                    class="buttonnew"
                    @click="handleDelete(scope.row)" />
                </el-tooltip>
                <el-tooltip class="item" content="产品详情" effect="light" placement="top">
                  <el-button
                    icon="el-icon-s-operation"
                    size="mini"
                    class="buttonnew"
                    @click="handleProductDetail(scope.row)" />
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页 -->
          <div class="page-box">
            <pagination :total="total" :page.sync="listQuery.pageNum" :size.sync="listQuery.pageSize" @pagination="getListPage" />
          </div>
          <!-- 分页 -->
        </div>
      </div>

      <div ref="main" class="tabmain" :class="{ secondmain: isActiveBtn }">
        <div class="cardLists">
          <!-- list 循环 -->
          <div v-for="(item,index) in list" :key="index" class="cardChild">
            <div class="product_img">
              <img src="@/assets/images/c6/product-img.png">
            </div>
            <div class="product_info">
              <div class="status">{{ item.state === '1' ? '禁用' : '启用' }}</div>
              <el-tooltip class="item" effect="light" placement="top-start">
                <div slot="content">{{ item.productName }}</div>
                <div class="title">{{ item.productName }}</div>
              </el-tooltip>
              <div class="props">
                <div class="flex" style="justify-content: space-between;">
                  <div class="prop">
                    <div class="label">产品类型</div>
                    <div class="value">{{ item.protocolTypeName }}</div>
                  </div>
                  <div class="prop">
                    <div class="label">协议类型</div>
                    <div class="value">{{ item.protocolType }}</div>
                  </div>
                </div>
                <div class="prop">
                  <div class="label">产品型号</div>
                  <div class="value">{{ item.model }}</div>
                </div>
              </div>
              <div class="button_box">
                <div class="btn" @click="handleDelete(item)">
                  <i class="el-icon-delete" />
                </div>
                <div class="line" />
                <div class="btn" @click="handleProductDetail(item)">
                  <i class="el-icon-s-operation" />
                </div>
              </div>
            </div>
          </div>

        </div>
        <div class="page-box">
          <pagination :total="total" :page.sync="listQuery.pageNum" :size.sync="listQuery.pageSize" @pagination="getListPage" />
        </div>
      </div>

      <product-detail :dialog="dialog" />
    </div>
  </div>
</template>

<script>

import { getListPage, deleteById } from '@/api/cms/winglinks/product'
import { tableMixin } from '@/utils/public'
import ProductDetail from './components/ProductDetail'

export default {
  name: 'WorkList',
  dicts: ['common_status'],
  components: {
    ProductDetail
  },
  mixins: [tableMixin],
  data() {
    return {
      // 表格高度
      height: 0,
      tableKey: 0,
      list: null,
      current: 1,
      total: 0,
      listLoading: false,
      isActiveBtn: true,
      // 顶部操作栏配置
      filterData: {
        productName: {
          key: 'productName',
          type: 'input',
          title: '产品名称',
          placeholder: '请输入产品名称'
        },
        model: {
          key: 'model',
          type: 'input',
          title: '产品型号',
          placeholder: '请输入产品型号'
        }
      },
      // 查询参数
      listQuery: {
        pageNum: 1,
        pageSize: 20,
        productName: null,
        model: null
      },

      dialog: {
        title: '产品详情',
        visible: false,
        disabled: false,
        loading: false,
        type: 'view',
        productId: null
      }
    }
  },
  computed: {
  },
  created() {
  },
  deactivated() {
  },
  mounted() {
    this.getListPage()
  },
  methods: {
    // 查询列表信息
    getListPage() {
      this.listLoading = true
      // 查询列表信息
      getListPage(this.listQuery).then(response => {
        this.list = response.rows
        this.total = response.total
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
      })
    },
    handleProductDetail: function(row) {
      this.productId = row.id
      this.$router.push({ path: '/cms/product/detail', query: { 'productId': row.id }})
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id
      this.confirmBox('是否确认删除产品编号为"' + ids + '"的数据项？').then(() => {
        // 删除信息
        deleteById(ids).then(() => {
          this.notifiySuccess('删除成功!')
          this.getListPage() // 查询列表信息
        })
      }).catch(() => {})
    },
    handleClickTab(tab) {
      if (tab === 'first') {
        this.isActiveBtn = true
      } else {
        this.isActiveBtn = false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
  .app-container{
    position: relative;
  }
  .app-containerInner{
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 0px 8px 0px rgba(34,52,94,0.16);
    height: 100%;
    padding: 20px;
    position: relative;
    /deep/ .filter-form__container .filter-item .el-form-item .el-form-item__content{
      height: 36px!important;
      line-height: 36px!important;
    }
    /deep/ .filter-form__container .filter-item .el-input{
      height: 36px!important;
      line-height: 36px!important;
    }
    /deep/ .filter-form__container .filter-item .el-input__inner{
      height: 36px!important;
      line-height: 36px!important;
    }
    /deep/ .el-form .searchBtns.el-button{
      padding: 10px 20px;
      background: #0082cd;
      border-color: #0082cd;
      color: #fff;
      border-radius: 2px;
    }
    /deep/ .el-form .searchBtns.el-button:hover{
      background: #0595e9;
      border-color: #0595e9;
    }
    /deep/ .el-button.buttonnew{
      border:none;
      padding:0;
      font-size: 20px;
      color: #0082CD;
      background: transparent;
    }
    /deep/ .el-table--border th{
      background: #dde7f2!important;
      border-color: #dde7f2!important;
      color: #000000;
      font-weight: bold;
      height: 44px;
    }
    /deep/ .el-table td.el-table__cell{
      height: 44px;
      color: #22335e;
    }
    /deep/ .el-table tr:nth-child(even){
      background: rgba(221,231,242,0.20);
    }
    .tabIcons{
      float:right;
      display: flex;
      align-items: center;
    }
    .tabBtnIcons{
      width: 36px;
      height: 36px;
      background: #dde7f2;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #9095A7;
      cursor: pointer;
      i{
        font-size: 20px;

      }
      &.activeIcon{
        background: #0082cd;
        color: #fff;
      }
    }
    .tabmain{
      display: none;
      height: calc(100% - 80px);
      &.firstmain{
        display:block;
        overflow: scroll;
      }
      &.secondmain{
        display:block;
        overflow: scroll;
      }
    }
  }
  .header{
    height: 25px;
    width: 200px;
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-bottom: 10px;
    .line{
      width: 5px;
      height: 90%;
      background-color: #00afff;
      margin-right: 10px;
      border-radius: 4px;
    }
    .text{
      line-height: 100%;
      font-weight: 600;
      font-size: 18px;
    }
  }

  // 卡片列表样式
  .cardLists {
    padding: 5px;
    /* 父盒子设置为伸缩盒子*/
    display: flex;
    /* wrap:  在必要的时候进行换行*/
    flex-wrap: wrap;
    /* flex-start:  默认从头开始排列*/
    justify-content: flex-start;
  }
  .cardChild {
    height: 196px;
    padding: 16px;
    background-color: #ffffff;
    overflow: hidden;
    box-shadow: 0 0 4px #00000026;
    border-radius: 8px;
    background-image: url("../../../../assets/images/c6/blue-bg.png");
    background-size: 104% 104%;
    background-repeat: no-repeat;
    /* 18%:  默认每一个列表占18%*/
    flex: 0 0 24%;
    /* 右边距，默认使用css函数去计算 */
    margin-right: calc(4% / 4);
    margin-bottom: 20px;
    position: relative;
    .status{
      width: 57px;
      height: 25px;
      border-radius: 6px 0 0 6px;
      font-size: 12px;
      font-weight: 500;
      line-height: 25px;
      text-align: center;
      position: absolute;
      right: 0;
      top: 16px;
      background: #d9dffd;
      color: #1966ff;
    }
    .product_img{
      position: absolute;
      right: 20px;
      top: 50px;
      img{
        cursor: pointer;
        width: 100px;
      }
    }
    .product_info{
      padding-left: 16px;
      max-width: calc(100% - 158px);
      .title{
        font-size: 18px;
        font-weight: 700;
        color: #050708;
        line-height: 40px;
        height: 40px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .props{
        margin-top: 10px;
        .flex{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
        }
        .prop{
          margin-bottom: 10px;
          .label{
            font-size: 12px;
            font-weight: 400;
            color: #666;
            line-height: 14px;
          }
          .value{
            font-size: 14px;
            font-weight: 600;
            color: #050708;
            line-height: 14px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 6px;
          }
        }
      }
      .button_box{
        display: flex;
        flex-direction: row;
        position: absolute;
        left: 16px;
        bottom: 16px;
        margin-top: 20px;
        width: 80px;
        height: 25px;
        border-radius: 40px;
        justify-content: space-around;
        padding: 0 10px;
        align-items: center;
        border: 3px solid #1a66ff;
        .line{
          width: 1px;
          height: 70%;
          background-color: #DCDFE6;
        }
        .btn{
          width: 15px;
          font-weight: bold;
          text-align: center;
          color: #1a66ff;
          i{
            font-weight: bold;
          }
        }
      }
    }
  }
  /* 去除每行尾多余的边距 */
  .cardChild:nth-child(4n) {
    margin-right: 0;
  }
</style>
